package br.com.salmos.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import br.com.salmos.vo.Versiculo;

public class TableSalmosENHelper {
    
    public static final String COL_ID = "id";
    public static final String COL_LIVRO = "livro";
    public static final String COL_CAPITULO = "capitulo";
    public static final String COL_VERSICULO = "versiculo";
    public static final String COL_TEXTO = "texto";
    public static final String COL_LIDO = "lido";
    
    
    
    
    private Context context;
    private SQLiteDatabase db;
    
    public TableSalmosENHelper(Context context) {
        this.context = context;
        //OpenHelper openHelper = new OpenHelper(this.context);
        Log.i("TableSalmosENHelper", "constructor");
        SQLOpenHelperSalmos openHelper = new SQLOpenHelperSalmos(context, true);             
        this.db = openHelper.getWritableDatabase();
    }
    
    public void insert(Versiculo versiuclo) {

        // clearDatabase();
         ContentValues values = new ContentValues();
         //values.put(COL_ID, nextID());
         values.put(COL_LIVRO, versiuclo.getLivro());
         values.put(COL_CAPITULO, versiuclo.getCapitulo());
         values.put(COL_VERSICULO, versiuclo.getVersiculo());
         values.put(COL_TEXTO, versiuclo.getTexto());
         values.put(COL_LIDO, 0);
        

         db.insert(OpenHelper.SALMOSEN_TABLE_NAME, null, values);
     }
    
    public void updateVersiculoLido(Versiculo versiculo){
        ContentValues args = new ContentValues();
        args.put(COL_LIDO, 1);
        db.update(OpenHelper.SALMOSEN_TABLE_NAME, args, COL_ID + "=" + versiculo.getId(), null);
    }
    
    public void updateTodosVersiculosNaoLido(){
        ContentValues args = new ContentValues();
        args.put(COL_LIDO, 0);
        db.update(OpenHelper.SALMOSEN_TABLE_NAME, args, null, null);
    }
    
    public void deleteAll(){
        db.delete(OpenHelper.SALMOSEN_TABLE_NAME, null, null);
    }
    
    public Cursor getVersiculosDesmarcados(){
            Cursor cursor = this.db.query(OpenHelper.SALMOSEN_TABLE_NAME, new String[] {"id,livro,capitulo,versiculo,texto,lido"}, null, null, null, null,
                "id desc");
            return cursor;
    }

}
